package com.ruoyi.project.infobaseprojectindex.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.infobaseprojectindex.vo.InfoBaseProjectIndexVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.infobaseprojectindex.domain.InfoBaseProjectIndex;
import com.ruoyi.project.infobaseprojectindex.service.IInfoBaseProjectIndexService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 基础库-项目库-指标Controller
 *
 * @author ruoyi
 * @date 2022-02-11
 */
@RestController
@RequestMapping("/infoBaseProjectIndex/infoBaseProjectIndex")
public class InfoBaseProjectIndexController extends BaseController {
    @Autowired
    private IInfoBaseProjectIndexService infoBaseProjectIndexService;

    /**
     * 查询基础库-项目库-指标列表
     */
    @PreAuthorize("@ss.hasPermi('infoBaseProjectIndex:infoBaseProjectIndex:list')")
    @GetMapping("/list")
    public TableDataInfo list(InfoBaseProjectIndex infoBaseProjectIndex) {
        startPage();
        List<InfoBaseProjectIndex> list = infoBaseProjectIndexService.selectInfoBaseProjectIndexList(infoBaseProjectIndex);
        return getDataTable(list);
    }

    /**
     * 导出基础库-项目库-指标列表
     */
    @PreAuthorize("@ss.hasPermi('infoBaseProjectIndex:infoBaseProjectIndex:export')")
    @Log(title = "基础库-项目库-指标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InfoBaseProjectIndex infoBaseProjectIndex) {
        List<InfoBaseProjectIndex> list = infoBaseProjectIndexService.selectInfoBaseProjectIndexList(infoBaseProjectIndex);
        ExcelUtil<InfoBaseProjectIndex> util = new ExcelUtil<InfoBaseProjectIndex>(InfoBaseProjectIndex.class);
        util.exportExcel(response, list, "基础库-项目库-指标数据");
    }

    /**
     * 获取基础库-项目库-指标详细信息
     */
    @PreAuthorize("@ss.hasPermi('infoBaseProjectIndex:infoBaseProjectIndex:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(infoBaseProjectIndexService.selectInfoBaseProjectIndexById(id));
    }

    /**
     * 新增基础库-项目库-指标
     */
    @PreAuthorize("@ss.hasPermi('infoBaseProjectIndex:infoBaseProjectIndex:add')")
    @Log(title = "基础库-项目库-指标", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InfoBaseProjectIndex infoBaseProjectIndex) {
        return toAjax(infoBaseProjectIndexService.insertInfoBaseProjectIndex(infoBaseProjectIndex));
    }

    /**
     * 修改基础库-项目库-指标
     */
//    @PreAuthorize("@ss.hasPermi('infoBaseProjectIndex:infoBaseProjectIndex:edit')")
    @Log(title = "基础库-项目库-指标", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InfoBaseProjectIndex infoBaseProjectIndex) {
        return toAjax(infoBaseProjectIndexService.updateInfoBaseProjectIndex(infoBaseProjectIndex));
    }

    /**
     * 删除基础库-项目库-指标
     */
//    @PreAuthorize("@ss.hasPermi('infoBaseProjectIndex:infoBaseProjectIndex:remove')")
    @Log(title = "基础库-项目库-指标", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(infoBaseProjectIndexService.deleteInfoBaseProjectIndexByIds(ids));
    }

    /**
     * 不分页获取
     *
     * @param projectId
     * @return
     */
    @RequestMapping(value = "/noPageList", method = RequestMethod.GET)
    public AjaxResult noPageList(@RequestParam("projectId") Long projectId) {
        InfoBaseProjectIndex infoBaseProjectIndex = new InfoBaseProjectIndex();
        infoBaseProjectIndex.setProjectId(projectId);
        List<InfoBaseProjectIndex> infoBaseProjectIndices = infoBaseProjectIndexService.selectInfoBaseProjectIndexList(infoBaseProjectIndex);
        return AjaxResult.success(infoBaseProjectIndices);
    }

    /**
     * 批量 插入项目指标
     *
     * @param baseProjectIndexVo
     * @return
     */
    @RequestMapping(value = "/batchInsertProjectIndex", method = RequestMethod.POST)
    public AjaxResult batchInsertProjectIndex(@RequestBody InfoBaseProjectIndexVo baseProjectIndexVo) {
        int i = infoBaseProjectIndexService.batchInsertBaseProjectIndex(baseProjectIndexVo);
        return toAjax(i);
    }
}
